package com.bds.btcdc.service;

import java.util.List;

import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bds.btcdc.config.NutzDaoConfig;
import com.bds.btcdc.model.CoinPairExchanges;

/**
 * Created by DongChenchen on 2018/4/13 0013
 */
@Service
public class CoinPairExchangesService {
	@Autowired
	private NutzDaoConfig dao;

	/**
	 * 查询channel交易所 支持对冲平台的币对
	 * 
	 * @return
	 */
	
	public List<CoinPairExchanges> getPairs(String exchange) {

		Sql sql = Sqls.create("Select b.* "
				+ "from t_coin_pair a,t_coin_pair_exchanges b where a.status=1 and a.en_pair_code=b.en_pair_code and b.exchange=@exchange");
		sql.params().set("exchange", exchange);
		sql.setCallback(Sqls.callback.entities());
		sql.setEntity(dao.getEntity(CoinPairExchanges.class));
		dao.execute(sql);
		List<CoinPairExchanges> list = sql.getList(CoinPairExchanges.class);
		return list;
	}

	/**
	 * 根据交易所的币对 查询对冲平台的币对
	 * 
	 * @return
	 */

	public String getBtcPair(String exchange, String pair) {
		Sql sql = Sqls.create("select a.en_pair_code " + "from t_coin_pair_exchanges a "
				+ "where UPPER(a.exchange)=@exchange and a.pair_code=@pair");
		sql.params().set("exchange", exchange.toUpperCase());
		sql.params().set("pair", pair);
		sql.setCallback(Sqls.callback.str());
		dao.execute(sql);
		return sql.getString();
	}

}
